<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/public/static/index/layui/css/layui.css">
    <script src="/public/static/index/js/jquery-3.4.1.min.js"></script>
</head>

<body>
    <form class="layui-form" style="margin-top: 50px;">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">学号</label>
            <div class="layui-input-block">
                <input type="number" name="number" onkeypress='return( /[\d]/.test(String.fromCharCode(event.keyCode)))' required lay-verify="required" placeholder="请输入学号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <div class="layui-btn" id="submit" lay-submit lay-filter="formDemo">立即提交</div>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script>
        $("#submit").click(function() {
            var name = $("input[name='name']").val();
            var number = $("input[name='number']").val();
            //var name = $(".name").val();
            //var number = $(".number").val();
            //alert(number);

            var url = 'user';
            postData = {
                'name': name,
                'number': number,
            };
            $.post(url, postData, function(result) {
                if (result.code == 1) {
                    alert('提交成功');
                }
            }, 'json');
        });
    </script>
</body>

</html>